物件(Objective)


Python世界都是物件

Python 和一些程式語言不一樣的地方在於在 Python 世界裡每個東西都是物件(object)。每個物件都具有屬性(attribute)方法(method)

  • 屬性(atrribute):從屬性中了解物件(object)的資訊
  • 方法(method):對物件進行的操作
    eg:
    車子的顏色、品牌即為屬性,前進、後退等操作即為方法

*字串物件''
當 name = 'Jack',''即為字串物件,而我們以name這個變數命名。

*方法upper
使用upper()方法,會將內容值轉為大寫回傳
eg:

print('Jack'.upper())
=>JACK

#其他可使用物件的函式可以透過dir來查詢
print(dir('jack'))

*隨堂練習:將字串物件轉成小寫

請使用字串物件內建的方法:lower() 將變數名稱為 amen的字串物件值轉成小寫值印出:

name = 'JACK'
print(name.lower())

內容參考:第19期Python程式設計入門共學營

#Python






你可能感興趣的文章

Day04:從函式看 bytecode

Day04:從函式看 bytecode

Web開發學習筆記05 — for Loop、while Loop & 遍歷陣列、物件

Web開發學習筆記05 — for Loop、while Loop & 遍歷陣列、物件

Leetcode  JS 2623. Memoize 簡易筆記

Leetcode JS 2623. Memoize 簡易筆記






留言討論